﻿using HoverTree.BLL;
using HoverTree.HoverTreeFrame;
using HoverTree.Model;
using System;
using System.Web;

namespace HoverTreeMobile.HvtAdmin
{
    public partial class PanelUserAlter : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (HttpContext.Current.User.Identity.Name != "hovertree")//超级管理员
            {
                Response.Redirect("index.aspx");
            }

            if (!IsPostBack)
            {
                int m_id = RequestHelper.GetQueryInt("hvtid", 0);

                string m_un = RequestHelper.GetQueryString("hvtun");

                PanelUserInfo m_info = new PanelUserInfo();
                HvtPanelUser m_bll = new HvtPanelUser();

                if (m_id < 1)
                {
                    if (m_un == string.Empty)
                    {
                        literalTips.Text = "不存在的用户";
                        buttonOK.Enabled = false;
                        return;
                    }
                    else
                    {
                        m_info = m_bll.GetByUserName(m_un);
                    }
                }
                else
                {
                    m_info = m_bll.Get(m_id);
                }

                if (m_info == null)
                {
                    literalTips.Text = "不存在的用户";
                    buttonOK.Enabled = false;
                    return;
                }
                ltlID.Text = m_info.HvtId.ToString();
                textBoxUserName.Text = m_info.Hvtusername;
                textWelcome.Text = m_info.HvtWelcome;
                // textBoxPassword.Text = m_info.Hvtpassword;
                //textBoxPassword.Attributes.Add("value", m_info.Hvtpassword);
            }
        }

        protected void buttonOK_Click(object sender, EventArgs e)
        {

            PanelUserInfo m_model = new PanelUserInfo();

            m_model.HvtId = Convert.ToInt32(ltlID.Text);
            m_model.Hvtusername = textBoxUserName.Text;
            m_model.HvtWelcome = textWelcome.Text;

            HvtPanelUser m_panelUser = new HvtPanelUser();
            literalTips.Text = m_panelUser.Alter(m_model);

            if (literalTips.Text == string.Empty)
                literalTips.Text = "修改成功";
        }
    }
}